Skip to content

Update Mapping Request Payload in controller.rst #18522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

yesworld
Copy link

@yesworld yesworld commented Jul 6, 2023

To make the Mapping Request Payload work properly, it is necessary to install the phpstan/phpdoc-parser and phpdocumentor/type-resolver components. Otherwise, nested DTOs within an array will not function correctly.

To see:
/symfony/framework-bundle/DependencyInjection/FrameworkExtension.php

To make the Mapping Request Payload work properly, it is necessary to install the phpstan/phpdoc-parser and phpdocumentor/type-resolver components. Otherwise, nested DTOs within an array will not function correctly.

To see:
/symfony/framework-bundle/DependencyInjection/FrameworkExtension.php
@javiereguiluz
Copy link
Member

Damir, thanks for this contribution.

In the file that you mentioned, I can see this:

https://github.com/symfony/symfony/blob/43066ff98d158946f6b5f8473802c9301f0abf49/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1956-L1968

But, can you please link to the code that shows that those dependencies are required for using this feature? I'm not an expert on this so I'd like to double check this before merging your contribution. Thanks!

@yesworld
Copy link
Author

yesworld commented Jul 13, 2023

I apologize for the inaccuracy, these dependencies are necessary if you want to use an array with nested objects.

Consider a following situation:

class ParentDto
{
    /**
     * @param NestedDto[] $nested
     */
    public function __construct(
        public readonly array $nested = []
    ) {}
}

class NestedDto
{
    public function __construct(public string $value) {}
}

If you install these 2 packages, $parentDto->nested will become a nested object array NestedDto[], instead of a regular array.

@OskarStark
Copy link
Contributor

I reworked your PR in #18936

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants